package com.example.wastes.article.controller;

import com.example.wastes.article.service.ArticleService;
import com.example.wastes.common.pojo.Article;
import com.example.wastes.common.util.R;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
public class ArticleController {
    @Autowired
    private ArticleService articleService;
    @GetMapping("/getAllArticle")
    @ApiOperation("分类查询所有")
    public R getAllArticle() {
        return new R(true,articleService.findAll());
    }
    @PostMapping("/saveArticle")
    @ApiOperation("添加分类")
    public R saveArticle(@RequestBody Article article) {
        return new R(articleService.save(article));
    }
    @PutMapping("/updateArticle")
    @ApiOperation("修改分类")
    public R updateArticle(@RequestBody Article article) {
        return new R(articleService.updateById(article));
    }
    @DeleteMapping("/deleteArticle")
    @ApiOperation("删除分类")
    public R deleteArticle(Integer id) {
        return new R(articleService.removeById(id));
    }
    //模糊查询
    @GetMapping("/findArticleName")
    @ApiOperation("通过名字查询")
    public R findArticleName(String name){
        return new R(true,articleService.findArticleName(name));
    }
}
